package com.erp.erp_project.core.util;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author the bright star
 */
@Component
public class DateConverter implements Converter<String, Date> {
    @Override
    public Date convert(String s) {
        Date date=new Date();
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (s!=null){
            try {
                date=sdf.parse(s);
            } catch (ParseException e) {
                throw new RuntimeException("格式不匹配");
            }
        }else {
            throw new RuntimeException("参数不能为空");
        }
        return date;
    }
}
